home *** CD-ROM | disk | FTP | other *** search
- Path: news.ov.com!news
- From: glenn@ov.com (Fletcher.Glenn@ov.com)
- Newsgroups: comp.lang.c
- Subject: Re: Please please help a newbie!!
- Date: 15 Feb 1996 23:40:48 GMT
- Organization: OpenVision
- Message-ID: <4g0ga0$sdm@spanky.pls.ov.com>
- References: <4fth5k$43v@pacifica.access.ch>
- Reply-To: glenn@ov.com
- NNTP-Posting-Host: foghorn.pls.ov.com
-
- In article 43v@pacifica.access.ch, tombeck@usemail.com (Thomas Beck) writes:
- >Hi there!
- >
- >It's quite embarrassing to ask those two questions, because they seem
- >absolutely stupid (they probably are). Yesterday I started to learn C/C++. I
- >bought a 700 pages book with a cd included that has two compilers on it). I
- >fully understand the chapter about the types, but the things I program just
- >can't be compiled. I extracted the following two problems:
- >
- >----------- example 1: -------------
- >int i;
- >int & a=i;
- >
- >main() {
- >}
- >--------------------------------------------
-
- In the above example, '&' is not a data type, it is an operator.
- If you want a integer pointer to 'i' you need to do the following:
-
- int i, *a;
-
- main(){
- a = &i;
- }
-
- >
- >This is not compiled, I get the following output with Symantec C++ 6.11:
- >
- >D:\SC>sc test1.c
- >
- >sccx test1.c
- >int & a=i;
- > ^
- >test1.c(2) : Error: '=', ';' or ',' expected
- >
- >--- errorlevel 1
- >
- >The second thing that doesn't work is this:
- >
- >----------- example 2: -------------
- >struct abc {
- > int i;
- > char a;
- > void f1() {
- > };
- >};
- >
- >main() {
- >}
- >---------------------------------------------
-
- In the example above, you cannot define a function in the body of a
- struct. If you want a pointer to a function, you need to do the following:
-
- struct abc{
- int i;
- char a;
- void (*f1)(); /* This reads as "f1 a pointer to a function returning void" */
- };
-
- main() {
- }
- Fletcher.Glenn@ov.com
-
-
- >This isn't compiled either, here's the output:
- >
- >D:\SC>sc test2.c
- >
- >sccx test2.c
- > void f1() {
- > ^
- >test2.c(4) : Error: illegal type for 'f1' member
- >
- >--- errorlevel 1
- >
- >
- >Before you think I'm absolutely stupid... I used to be very good at Pascal
- >(TP 6.0), and I'm also experienced in OOP under Pascal. I have no clue of
- >C++, however, and I can only rely on what's written in that book. Apparently
- >it doesn't tell me the truth, does it?
- >
- >Can you please help me with those two problems (referenced variable and
- >function within a class), so that I can go on and learn a few more difficult
- >things?
- >
- >Thanks in advance,
- >
- >Thomas Beck, tombeck@usemail.com
- >
- >=================================================================
- >Summer's day, as she passed away. Birds were singing in the
- >summer sky; then came the rain, and once again, a tear fell
- >from her mother's eye...
- >=================================================================
- >
-
-
-
-
-
-